#include using namespace std; //HOMEWORK - complete the following functions and test them //from the main function. //You are responsible for completing and testing these functions //sameString, copyString, appendString and reverse. //The main function should simply call each of these functions //using simple test cases to show that the work. //return the number of char's before the \0 int stringLength(char s[]); //return true if they have all the same char's before the \0 bool sameString(char s1[], char s2[]); //assume that the source is a valid c-style string //assume that the destination is big enough to hold the source void copyString(char destination[], char source[]); //append, concatenate void appendString(char destination[], char source[]); //return true if s has the character query bool contains(char s[], char query); //return true if s has the string query bool contains(char s[], char query[]); void reverse(char s[]); void main() { char s1[100]; cin >> s1; cout << stringLength(s1) << endl; char s2[100]; //s2 = s1; // bad //copyString(s2, s1); if(contains(s1,"on")) { cout << "found it" << endl; } } int stringLength(char s[]) { int i = 0; while(s[i] != '\0') { i++; } return i; } bool contains(char s[], char query) { bool foundQuery = false; for(int i = 0;s[i] != '\0' && !foundQuery;i++) { if(s[i] == query) { foundQuery = true; } } return foundQuery; } bool contains(char s[], char query[], int startIndex) { bool result = true; int queryLength =stringLength(query); int queryIndex = 0; for(int i = startIndex; i < startIndex + queryLength; i++, queryIndex++) { if(s[i] != query[queryIndex]) { result = false; } } return result; } bool contains(char s[], char query[]) { bool foundQuery = false; int length = stringLength(s) - stringLength(query) + 1; for(int i = 0;i < length && !foundQuery;i++) { if(contains(s,query,i)) { foundQuery = true; } } return foundQuery; }